package J11_9.J11_8.operation;

import J11_9.J11_8.book.BookList;

import java.util.Scanner;

public class DeleteBook implements IOperation {

    @Override
    public void work(BookList bookList){
        System.out.println("删除图书");

        Scanner in = new Scanner(System.in);
        System.out.println("请输入书名");
        String name = in.nextLine();
        for (int i = 0; i < bookList.getBookCount(); i++) {
            if(bookList.getBooks(i).getName().equals(name)) {
                for(int j = i; j < bookList.getBookCount() - 1;j++) {
                    bookList.setBooks(j, bookList.getBooks(j+1));
                }
                bookList.setBookCount(bookList.getBookCount() - 1);
                System.out.println("删除成功");
                return;
            }
        }
        System.out.println("找不到这本书");
    }
}
